package models;

import java.util.*;

import javax.persistence.*;

import com.avaje.ebean.Ebean;
import com.avaje.ebean.SqlQuery;
import com.avaje.ebean.SqlRow;

import play.db.ebean.*;
import play.data.format.*;
import play.data.validation.*;


/**
 * User entity managed by Ebean
 */
@Entity
@Table(name="examination")
public class Examination extends Model {

	public static final long serialVersionUID = 1L;

	@Id
	@Column(name="idexamination")
	public long id;

    @Column(name="examination_name")
    public String examinationName;

    @Column(name="examination_type")
    public String examinationType;

    @Column(name="examination_subtype")
    public String examinationSubtype;

    @Column(name="measure_unit")
    public String measureUnit;

    // -- Queries

    public static Model.Finder<String,Examination> find = new Model.Finder(String.class, Examination.class);

    public static List<Examination> getExaminations() {
        return find
        	.where()
        	.orderBy("examination_subtype")
            .findList();
    }
    
    public static List<String> getDistinctExaminations () {
    	String sql = "select distinct examination_subtype from examination ";
    	SqlQuery sqlQuery = Ebean.createSqlQuery(sql);
    	List<SqlRow> rows = sqlQuery.findList();
    	List<String> names= new ArrayList<String>(rows.size());
        for (SqlRow row : rows){
        	names.add(row.getString("examination_subtype"));
        }

         return names;
    }
    
    public static List<Examination> getExaminationList() {
        return find
               .findList();
    }

}

